# -*- coding: utf-8 -*-
grades = [{'name': 'wang', 'subject': 's', 'score': 99}]

def add():
    name = input('输入要添加学生成绩姓名：')
    subject = input('输入要添加学生成绩科目：')
    score = int(input('输入该学生成绩：'))
    msg = {'name':name,'subject':subject,'score':score}
    grades.append(msg)

def sel():
    name = input('输入要查询学生成绩姓名：')
    subject = input('输入要查询学生成绩科目：')
    for i in grades:
        if i['name'] == name and i['subject'] == subject:
            print(f'{name}的{subject}成绩为{i["score"]}')
        else:
            print(f'查询不到{name}的{subject}成绩')

def updata():
    name = input('输入要更新学生成绩姓名：')
    subject = input('输入要更新学生成绩科目：')
    score = int(input('要将该学生该科目成绩更新为：'))
    for i in grades:
        if i['name'] == name and i['subject'] == subject:
            i['score']=score
            print(f'修改后成绩为{i}')
        else:
            print(f'查询不到{name}的{subject}成绩,无法修改')

def del_score():
    name = input('输入要删除学生成绩姓名：')
    subject = input('输入要删除学生成绩科目：')
    index = 0
    for i in grades:

        if i['name'] == name and i['subject'] == subject:
            del grades[index]
        else:
            print(f'查询不到{name}的{subject}成绩,无法删除')
        index += 1

def show_all():
    print(f'name'.ljust(10) + f'subject'.ljust(10) + f'score'.ljust(10))
    for i in grades:
        print(f'{i["name"]}'.ljust(10)+f'{i["subject"]}'.ljust(10)+f'{i["score"]}'.ljust(10))

def stu_score_manege():
    print('''学生成绩管理系统

1. 添加学生成绩
2. 查询学生成绩
3. 更新学生成绩
4. 删除学生成绩记录
5. 显示所有学生成绩
6. 退出系统''')
    in_str = input('选择你要进行的操作：')
    if in_str.isdigit() and int(in_str)>=1 and int(in_str)<=6:
        act = int(in_str)
        if act==1:
            add()
            stu_score_manege()
        elif act ==2:
            sel()
            stu_score_manege()
        elif act ==3:
            updata()
            stu_score_manege()
        elif act ==4:
            del_score()
            stu_score_manege()
        elif act ==5:
            show_all()
            stu_score_manege()
        elif act ==6:
            return 0
    else:
        print('请输入正确指令：')
        stu_score_manege()


if __name__ == '__main__':
    stu_score_manege()
